<?php

	get_header();
	
?>
        
        <!-- MIDDLE -->
        <section class="middle row">
		
            <!-- PORTFOLIO WRAP -->
            <div class="portfolio-wrap span12">
				
                <!-- PAGE HEADER -->
				<?php
				
					$for_top_cats = get_categories( array( 'type' => 'portfolio', 'taxonomy' => 'department' ) );
					$for_top_cat_out = '';
					
					foreach ( $for_top_cats as $for_top_cat ) :
						
						if ( single_cat_title( '', false ) == $for_top_cat->name )
						{
							$for_top_cat_out = $for_top_cat->description;
						}

					endforeach;
				
				?>
				
                <div class="page-header">
				
					<h1>
					
						<b><?php single_cat_title(); ?></b>
						
						<small><?php echo $for_top_cat_out; ?></small>
						
					</h1>
					
				</div>
                <!-- end PAGE HEADER -->

                <!--FILTERS-->
				<?php
				
					$for_sub_cats = get_categories( array( 'type' => 'portfolio', 'taxonomy' => 'department' ) );
					$for_sub_cat_out = '';
					
					foreach ( $for_sub_cats as $for_sub_cat ) :
						
						if ( single_cat_title( '', false ) == $for_sub_cat->name )
						{
							$for_sub_cat_out = $for_sub_cat->term_taxonomy_id;
						}

					endforeach;
					
					$pf_terms = get_categories( array( 'type' => 'portfolio', 'taxonomy' => 'department', 'parent' => $for_sub_cat_out ) );
				?>
				
                <ul id="filters">
				
					<?php
					
						if ( count( $pf_terms ) >= 1 )
						{
							?>
							
								<li class="current">
								
									<a href="#" data-filter="*"><?php echo __( 'all', 'responsy' ); ?></a>
									
								</li>
								
							<?php
						}
					
					?>
					
					<?php
					
						foreach ( $pf_terms as $pf_term ) :
						
							?>
					
								<li>
									<a href="#" data-filter=".<?php echo $pf_term->slug; ?>"><?php echo $pf_term->name; ?></a>
								</li>
						
							<?php
						
						endforeach;
					
					?>
					
                </ul>
                <!-- end FILTERS -->
				
                <!-- PORTFOLIO -->
                <div id="portfolio" class="portfolio-items">
					
					<?php
					
						$args_department = array( 'post_type' => 'portfolio', 'department' => single_cat_title( '', false ), 'posts_per_page' => -1 );
						$loop_department = new WP_Query( $args_department );
							
						if ( $loop_department->have_posts() ) :
							
							while ( $loop_department->have_posts() ) : $loop_department->the_post();
								
								$terms = get_the_terms( $post->ID, 'department' );
								$on_draught = '';
								
								if ( $terms && ! is_wp_error( $terms ) ) :
									
									$draught_links = array();

									foreach ( $terms as $term )
									{
										$draught_links[] = $term->slug;
									}
							
									$on_draught = join( " ", $draught_links );
									
								endif;
							
								?>
						
								<div class="item <?php echo $on_draught; ?>">
									<div class="media-box">
										<?php
											if ( has_post_thumbnail() )
											{
												$the_post_img_alt = get_the_title();
												the_post_thumbnail( 'portfolio_list_img', array( 'alt'	=> "$the_post_img_alt", 'title'	=> "" ) );
											}
											else
											{
												?><img src="<?php echo get_template_directory_uri(); ?>/img/blog/blog-placeholder.png" alt="<?php the_title(); ?>"><?php
											}
										?>
										<div class="mask">
											<h3 class="title"><?php echo __( 'SEE PROJECT DETAILS', 'responsy' ); ?></h3>
											<a href="<?php the_permalink(); ?>" class="ico full"></a>
										</div>
									</div>
									<h3 class="project-title"><?php the_title(); ?></h3>
									<p class="category"><?php echo get_post_meta( $post->ID, 'short_description', true ); ?></p>
								</div>
							
								<?php
							
							endwhile;
							
						endif;
						
						wp_reset_query();
					
					?>
					
                </div>
                <!-- end PORTFOLIO -->
				
            </div>
            <!-- end PORTFOLIO WRAP -->
			
        </section>
        <!-- end MIDDLE -->
		
    </div>
    <!-- end CONTAINER -->
   
<?php

	get_footer();
	
?>